﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Data;

/// <summary>
/// Summary description for RegistarNaImoti
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class RegistarNaImoti : System.Web.Services.WebService {

    public RegistarNaImoti () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return null;
    }


    //Proveri imot - za daden igrac proveruva koi polinja gi poseduva - gi vraka iminjata na polinjata, ako igracot nema polinja vraka null
    [WebMethod]
    public string[] proveriImot(string ime_igrac)
    {
        string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Proekt.mdb;"; //postavuvame "adresa" do bazata
        OleDbConnection conn = new OleDbConnection(conString);
        conn.Open();

        string select = "SELECT POLINJA.IME FROM POLINJA, IGRACI WHERE IGRACI.IME = ? AND IGRACI.ID = POLINJA.IGRACID";
        OleDbCommand select_pole = new OleDbCommand(select, conn);
        select_pole.Parameters.AddWithValue("?", ime_igrac);

        OleDbDataReader reader = select_pole.ExecuteReader();


        int n = 0;

        while (reader.Read())
        {
            n++;

        }

        string[] polinja = new string[n];
        reader.Close();

        OleDbDataReader reader2 = select_pole.ExecuteReader();

        if (reader2.HasRows)
        {
            int i = 0;
            while (reader2.Read())
            {
                polinja[i] = reader2.GetValue(0).ToString();
                i++;
            }
            reader2.Close();
            conn.Close();
            return polinja;
        }
        else
        {
            return null;
        }

    }

    //Proveri kuki - za dadeno pole proveruva kolku kuki ima izgradeno
    [WebMethod]
    public int proveriKuki(string ime_pole)
    {
        string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Proekt.mdb;"; //postavuvame "adresa" do bazata
        OleDbConnection conn = new OleDbConnection(conString);
        conn.Open();

        string select = "SELECT KUKI FROM POLINJA WHERE IME = ?";
        OleDbCommand select_pole = new OleDbCommand(select, conn);
        select_pole.Parameters.AddWithValue("?", ime_pole);

        int kuki = Int32.Parse(select_pole.ExecuteScalar().ToString());

        return kuki;

    }

    //Proveri hotel - za dadeno pole proveruva kolku hoteli ima izgradeno
    [WebMethod]
    public int proveriHoteli(string ime_pole)
    {
        string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Proekt.mdb;"; //postavuvame "adresa" do bazata
        OleDbConnection conn = new OleDbConnection(conString);
        conn.Open();

        string select = "SELECT HOTEL FROM POLINJA WHERE IME = ?";
        OleDbCommand select_pole = new OleDbCommand(select, conn);
        select_pole.Parameters.AddWithValue("?", ime_pole);

        int hotel = Int32.Parse(select_pole.ExecuteScalar().ToString());

        return hotel;
    }
    
}
